Note.toJSON   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
var GedcomX = require('../'),
2
    utils = require('../utils');
3
4
/**
5
 * A note about a resource.
6
 * 
7
 * @see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#note|GEDCOM X JSON Spec}
8
 * 
9
 * @class
10
 * @extends ExtensibleData
11
 * @param {Object} [json]
12
 */
13
var Note = function(json){
14
  
15
  // Protect against forgetting the new keyword when calling the constructor
16
  if(!(this instanceof Note)){
17
    return new Note(json);
18
  }
19
  
20
  // If the given object is already an instance then just return it. DON'T copy it.
21
  if(Note.isInstance(json)){
22
    return json;
23
  }
24
  
25
  this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
26
};
27
28
Note.prototype = Object.create(GedcomX.ExtensibleData.prototype);
29
30
Note._gedxClass = Note.prototype._gedxClass = 'GedcomX.Note';
31
32
Note.jsonProps = [
33
  'lang',
34
  'subject',
35
  'text',
36
  'attribution'
37
];
38
39
/**
40
 * Check whether the given object is an instance of this class.
41
 * 
42
 * @param {Object} obj
43
 * @returns {Boolean}
44
 */
45
Note.isInstance = function(obj){
46
  return utils.isInstance(obj, this._gedxClass);
47
};
48
49
/**
50
 * Initialize from JSON
51
 * 
52
 * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
53
 * @return {Note} this
54
 */
55
Note.prototype.init = function(json){
56
  
57
  GedcomX.ExtensibleData.prototype.init.call(this, json);
58
  
59
  if(json){
60
    this.setLang(json.lang);
61
    this.setSubject(json.subject);
62
    this.setText(json.text);
63
    this.setAttribution(json.attribution);
64
  }
65
  return this;
66
};
67
68
/**
69
 * Get the language identifier.
70
 * 
71
 * @returns {String} lang
72
 */
73
Note.prototype.getLang = function(){
74
  return this.lang;
75
};
76
77
/**
78
 * Set the language identifier.
79
 * 
80
 * @param {String} lang
81
 * @returns {Note} This instance.
82
 */
83
Note.prototype.setLang = function(lang){
84
  this.lang = lang;
85
  return this;
86
};
87
88
/**
89
 * Get the subject.
90
 */
91
Note.prototype.getSubject = function(){
92
  return this.subject;
93
};
94
95
/**
96
 * Set the subject.
97
 * 
98
 * @param {String} subject
99
 * @returns {Note} This note.
100
 */
101
Note.prototype.setSubject = function(subject){
102
  this.subject = subject;
103
  return this;
104
};
105
106
/**
107
 * Get the text.
108
 * 
109
 * @returns {String} text
110
 */
111
Note.prototype.getText = function(){
112
  return this.text;
113
};
114
115
/**
116
 * Set the text.
117
 * 
118
 * @param {String} text
119
 * @returns {Note} This note.
120
 */
121
Note.prototype.setText = function(text){
122
  this.text = text;
123
  return this;
124
};
125
126
/**
127
 * Get the attribution.
128
 * 
129
 * @returns {Attribution}
130
 */
131
Note.prototype.getAttribution = function(){
132
  return this.attribution;
133
};
134
135
/**
136
 * Set the attribution
137
 * 
138
 * @param {Object|Attribution} attribution
139
 * @returns {Note} This instance.
140
 */
141
Note.prototype.setAttribution = function(attribution){
142
  if(attribution){
143
    this.attribution = new GedcomX.Attribution(attribution);
144
  }
145
  return this;
146
};
147
148
/**
149
 * Export the object as JSON
150
 * 
151
 * @return {Object} JSON object
152
 */
153
Note.prototype.toJSON = function(){
154
  return this._toJSON(GedcomX.ExtensibleData, Note.jsonProps);
155
};
156
157
module.exports = Note;